import { Vec3 } from 'cc';
import { Point } from '../ai/ts-geometry-2d/Point';
import { EventManager } from '../core/EventManager';
import { TableAtrribute } from '../core/TableAttribute';

export class HumanSetBallSimulation {
  private timestamp = 0;
  private randTime = 30;
  // 启动模拟过程
  public startSimulation() {
    this.timestamp = 0;
    this.randTime = Math.ceil(Math.random() * 60) + 10;
  }

  public simulateHuman(targetPoint: Point) {
    this.timestamp += 1;
    // 1. 先放在目标位置周边，后续在进行一次微调在放在目标位置
    if (this.timestamp === this.randTime) {
      const pos = new Vec3(targetPoint.x, TableAtrribute.DeskTopAxisY, targetPoint.y);
      EventManager.Instance().Emit("ResetMainBallPosition", pos);
      // 每次自由球调整位置后，都需要快速瞄准目标
      EventManager.Instance().Emit('HideQiuGanAimCommponent', {});
    }
    // 2. 白球
    if (this.timestamp === 10 + this.randTime) {
      const pos = new Vec3(targetPoint.x, TableAtrribute.DeskTopAxisY, targetPoint.y);
      EventManager.Instance().Emit('ShowQiuGanAimCommponent', {});
      EventManager.Instance().Emit("HitBallHasChoosed", pos);
    }
  }

  public isEndSimulation() {
    return this.timestamp >= 2 * this.randTime + 1;
  }
}

